/*
 * Vector2.cpp
 *
 *  Created on: Jan 21, 2011
 *      Author: Helpful Learn Group
 */

#include "Vector2.h"

// Add other methods later

namespace GSP280
{

	//C004: COPY CONSTRUCTOR
	Vector2::Vector2(const Vector2 &vect2) {
		this->x = vect2.x;
		this->y = vect2.y;
	}

	//C005: ASSIGNMENT OPERATOR
	Vector2 & Vector2::operator= ( const Vector2 &vect2 )
	{
		//check for self assignment
		if ( this != &vect2 )
		{
			this->x = this->y = 0; //clear member contents

			this->x = vect2.x;
			this->y = vect2.y;
		}
		//
		return *this;
	}

	//M001: Set Location
	void Vector2::setVector2(const Vector2 &vect2) {
		this->x = vect2.x;
		this->y = vect2.y;
	}

	//M002: Set x-value, y-value
	void Vector2::setVector2(const float &_x, const float &_y) {
		this->x = _x;
		this->y = _y;
	}

	//M003: Get Location
	const Vector2 Vector2::getVector2() const {
		return (Vector2(this->x, this->y));
	}

	//M004: Set x-value
	void Vector2::setX(const float &_x) {
		this->x = _x;
	}

	//M005: Get x-value
	const float Vector2::getX() const {
		return (this->x);
	}

	//M006: Set y-value
	void Vector2::setY(const float &_y) {
		this->y = _y;
	}

	//M007: Get y-value
	const float Vector2::getY() const {
		return (this->y);
	}

	//M008: Addition operator
	const Vector2 Vector2::operator +(const Vector2 &r) {
		return (Vector2((this->x + r.x), (this->y + r.y)));
	}

	//M009: Subtraction operator
	const Vector2 Vector2::operator -(const Vector2 &r) {
		return (Vector2((this->x - r.x), (this->y - r.y)));
	}

	//M010: Multiplication operator
	const Vector2 Vector2::operator *(const float &scalar) {
		return (Vector2((this->x * scalar), (this->y * scalar)));
	}

	//M011: Convert Location from +ve to -ve
	const Vector2 Vector2::operator -() const {
		return (Vector2((-this->x), (-this->y)));
	}

	//M012: Increment Location by a given vector
	const Vector2 & Vector2::operator +=(const Vector2 &r) {
		this->x += r.x;
		this->y += r.y;

		return *this;
	}

	//M013: Decrement Location by a given vector
	const Vector2 & Vector2::operator -=(const Vector2 &r)
	{
		this->x -= r.x;
		this->y -= r.y;

		return *this;
	}

	const float Vector2::magnitude() {
			return (sqrt((this->x * this->x) + (this->y * this->y)));	
	}

	Vector2 Vector2::normalize() {
		return (Vector2((this->x / magnitude()), (this->y / magnitude())));
	}

	const float Vector2::dotProduct(Vector2 const &vec1)
	{
		Vector2 vec2;
		vec2.x = this->x * vec1.x;
		vec2.y = this->y * vec2.y;

		// returns a scalar
		return (vec2.x + vec2.y);
	}

	const float Vector2::crossProduct(const Vector2 &vec1) const
	{
		return ((this->x * vec1.y) - (this->y * vec1.x));
	}

	//const Vector2 Vector2::crossProduct(const Vector2 &vec1) const			// FIX THIS LATER ON
	//{
	//	return Vector2(vec1.y, -vec1.x);
	//}



}//namespace








/*
//======================================================
 void Vector2::setVector2(const Vector2 &vect2)
 {
 x = vect2.getX();
 y = vect2.getY();
 }

 void Vector2::setVector2(const float &x, const float &y)
 {
 x = x;
 y = y;
 }

 void Vector2::setX(const float &x)
 {
 x = x;
 }

 void Vector2::setY(const float &y)
 {
 y = y;
 }

 const Vector2 Vector2::getVector2() const
 {
 return Vector2(getX(), getY());// ?? would this work??
 }

 const float Vector2::getX() const
 {
 return x;
 }

 const float Vector2::getY() const
 {
 return y;
 }

 Vector2::~Vector2 ( )
 {
 // TODO Auto-generated destructor stub
 }

 Vector2::Vector2(const Vector2 &vect2) // Copy Constructor
 {
 x = vect2.getX();				// setVector2(const Vector2 &vect2)
 y = vect2.getY();				// does the same thing already??
 }

 Vector2 Vector2::operator =(const Vector2 &vect2) // assignment operator
 {

 }

 // Overloaded methods go here
 Vector2 Vector2::operator +(const Vector2 &l, const Vector2 &data) // Addition operator
 {
 return Vector2(l.getX() + data.getX(), l.getY() + data.getY());
 }

 Vector2 Vector2::operator -(const Vector2 &l, const Vector2 &data) // Subtraction operator
 {
 return Vector2(l.getX() - data.getX(), l.getY() - data.getY());
 }
 */
